package mapro

import (
	"github.com/go-martini/martini"
	"github.com/martini-contrib/render"
	"io/ioutil"
	// "io"
	"fmt"
	"net/http"
	"server/lib/Imartini"
	"server/lib/upload"
	mp "server/web/model/test/mapro"
)

func test2(req *http.Request, c martini.Context, mlog *Imartini.Mlog) string {
	req.ParseMultipartForm(100)

	fmt.Println(req.MultipartForm)

	ri, _ := ioutil.ReadAll(req.Body)
	ret, _ := upload.SaveFile(ri)
	return ret
}

func update_product(r render.Render, log *Imartini.Mlog) {
	r.HTML("test/mapro/update_product.html", map[string]interface{}{})
}

func post_update_product(res http.ResponseWriter, req *http.Request, c martini.Context, mlog *Imartini.Mlog) (string, error) {
	// f, _, err := req.FormFile("UpLoadFile")
	// if err == nil {
	// 	defer f.Close()
	// 	b, _ := ioutil.ReadAll(f)
	// 	str := fmt.Sprintf("%s", b)
	// 	mp.Update_product(str)
	// } else {
	// 	mlog.Printf("%s", err)
	// }

	return upload.Save(req, "UpLoadFile")
}

func select_product(res http.ResponseWriter, params martini.Params, mlog *Imartini.Mlog) string {
	res.Header().Add("Access-Control-Allow-Origin", "*")
	stock := mp.Select_product(params["id"])

	return stock
}
